/*======================我的飞机=======================*/
var MyPlane = {
	show:function(){
		this.init();
		this.autoFire();
		this.move();
	},
	init:function(){
		this.ele = document.createElement("div");
		this.ele.className = "my-warplain";
		document.body.appendChild(this.ele);
		//初始位置
		this.ele.style.left = GameEngine.bg.left() + (GameEngine.bg.width() - this.ele.offsetWidth)/2 + "px"; 
		this.ele.style.top = GameEngine.bg.height() - this.ele.offsetHeight + "px"; 
	},
	autoFire:function(){
		setInterval(function(){
			new Bullet().init().shoot();
		},this.frequency);
	},
	move:function(){
		document.onmousemove = function(e){
			var e = e || event;
			var mousex = e.clientX;
			var mousey = e.clientY;
			var minleft = GameEngine.bg.left();
			var maxleft = GameEngine.bg.left() + GameEngine.bg.width() - this.width();
			var mintop = 0;
			var maxtop = GameEngine.bg.height() - this.height();
			_left = mousex - this.width()/2;
			_top = mousey - this.height()/2;
			_left = Math.min(Math.max(minleft,_left),maxleft);
			_top = Math.min(Math.max(0,_top),maxtop);
			this.ele.style.left = _left + "px";
			this.ele.style.top = _top + "px";
			//记录我的飞机的中心点的位置
			this.pos = {x:this.left()+this.width()/2,y:this.top()+this.height()/2}
			//
			this.collision();
		}.bind(this);
	},
	collision:function(){
		//碰撞检测,我的飞机的中心点是否和敌人相撞
		GameEngine.enemies
		this.pos
		for(var i in GameEngine.enemies){
			var _left = GameEngine.enemies[i].left();
			var _right = GameEngine.enemies[i].left() + GameEngine.enemies[i].width();
			var _top = GameEngine.enemies[i].top();
			var _bottom = GameEngine.enemies[i].top()+GameEngine.enemies[i].height();
			//判断是否相撞
			if(this.pos.x>_left && this.pos.x<_right && this.pos.y>_top && this.pos.y<_bottom){
				this.explode();//我的飞机爆炸
			}
		}
	},
	explode:function(){
		this.destroy();
	},
	destroy:function(){
		
		
		GameEngine.gameover();
	},
	left:function(){
		return this.ele.offsetLeft;
	},
	top:function(){
		return this.ele.offsetTop;
	},
	width:function(){
		return this.ele.offsetWidth;
	},
	height:function(){
		return this.ele.offsetHeight;
	}
}